 
#include "lcdio.h"


#define s32p(s) (*((s32*)(s)))

#ifdef debug
u8   stemp[100];
#define 	_csdisbuf		stemp  
#else
#include "PublicSet1.h"
extern 		strRamData RamData;  
#define 	_csdisbuf		RamData.Disp.DispData  
#endif
 
void InitDisp(void)
{
	
	CLK->PCKENR2 |=  CLK_PCKENR2_LCD|CLK_PCKENR2_RTC;
	CSSLSE->CSR = CSSLSE_CSR_SWITCHEN|CSSLSE_CSR_CSSEN;
	CLK->ICKCR |= CLK_ICKCR_LSION; //LSI ON, LCD USE
	while((!CLK->ICKCR&CLK_ICKCR_LSIRDY)); 
 
	CLK->CRTCR = 4;
	while(CLK->CRTCR & 0x01);  
		

	LCD->CR3 = 0x00; //lcd en
	LCD->CR2 = 0x7c ; //0x70|(FData.DftSet.MSet.DispCR2<<1);
	LCD->FRQ = 0x08;
	LCD->CR4 = 0x03; //1/8 duty, 1/4 bias

	LCD->PM[0] = 0xcd;
	LCD->PM[1] = 0xE3;
	LCD->PM[2] = 0x23;
	LCD->PM[3] = 0XEC;

	LCD->CR3 = 0x55 ;// 0x40|(FData.DftSet.MSet.DispCR3&7);
}

 

void	CloseDisp(void){
	LCD->CR3 = 0x00;
	LCD->CR2 = 0x00;
	LCD->CR4 = 0x00;
}


void	UpdateDisp(void){
	u8 *csp;
	u8 n, a, d;
	s32 z;

	LCD->CR4 = 0x03;
	csp = 	_csdisbuf	;
	n = 0;
	do{
		LCD->RAM[n] = *csp++;
	}while(++n < 14);
	n = 0;
	LCD->CR4 = 0x07;
	do{
		LCD->RAM[n] = *csp++;
	}while(++n < 14);

	z = s32p(_csdisbuf+27);
	d = 0;
	while(d < 2){
		if(d==0){
			LCD->CR4 = 0x03;
		}else{
			LCD->CR4 = 0x07;
		}
		n = 14;
		while(n < 22){
			a = z;
			a &= 7;
			a <<= 1;
			LCD->RAM[n] = a;
			n++;
			n++;
			z >>= 3;
		}
		d++;
	}
}

 
/*

void main()
{

	InitDisp();
	UpdateDisp();
	
	while (1);
}
*/

